package com.gdut.Demo3;

import java.util.Scanner;

public class creat {
    public static void main(String[] args) {
        int[] arr = new int[0];
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.print("输入数组数字：");
            arr = creatArr(arr);
            System.out.print("是否继续输入，输入0退出，其他数字继续：");
            int flag = sc.nextInt();
            if (flag == 0) {
                break;
            }
        }
        System.out.println("构造的数组为：");
        for (int i : arr) {
            System.out.print(i + " ");
        }
    }

    public static int[] creatArr(int[] arr) {
        int[] newArr = new int[arr.length + 1];
        for (int i = 0; i < arr.length; i++) {
            newArr[i] = arr[i];
        }
        Scanner sc = new Scanner(System.in);
        newArr[arr.length] = sc.nextInt();
        return newArr;
    }
}
